﻿<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>简单计算器（原创）-jq22.com</title>
<script src="https://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
<style>
#showdiv {
	border:solid 1px;
	border-radius:10px;
	width:320px;
	height:400px;
	text-align:center;
	margin:auto;
	margin-top:50px;
	background-color:whitesmoke;
}
input[type=text] {
	margin-top:20px;
	width:290px;
	height:34px;
	font-size:20px;
	font-family:"微软雅黑";
}
input[type=button] {
	width:60px;
	height:60px;
	margin-top:20px;
	margin-left:5px;
	margin-right:5px;
	border-radius:90px;
	font-size:20px;
}
input[type=button]:hover {
	width:60px;
	height:60px;
	margin-top:20px;
	margin-left:5px;
	margin-right:5px;
	border-radius:90px;
	font-size:20px;
	border-color:blue;
}
</style>
</head>
<body>
<div id="showdiv">
    <input type="text" name="" id="inp" value="" readonly="readonly"><br>
    <input type="button" name="" id="" value="7" onclick="test(this)">
    <input type="button" name="" id="" value="8" onclick="test(this)">
    <input type="button" name="" id="" value="9" onclick="test(this)">
    <input type="button" name="" id="" value="+" onclick="test(this)"><br>
    <input type="button" name="" id="" value="4" onclick="test(this)">
    <input type="button" name="" id="" value="5" onclick="test(this)">
    <input type="button" name="" id="" value="6" onclick="test(this)">
    <input type="button" name="" id="" value="-" onclick="test(this)"><br>
    <input type="button" name="" id="" value="1" onclick="test(this)">
    <input type="button" name="" id="" value="2" onclick="test(this)">
    <input type="button" name="" id="" value="3" onclick="test(this)">
    <input type="button" name="" id="" value="*" onclick="test(this)"><br>
    <input type="button" name="" id="" value="c" onclick="test(this)">
    <input type="button" name="" id="" value="0" onclick="test(this)">
    <input type="button" name="" id="" value="=" onclick="test(this)">
    <input type="button" name="" id="" value="/" onclick="test(this)">

</div>

<script>
function test(btn) {
    //获取button按钮对象
    var num = btn.value;

    //将按钮的值赋给input输入框
    switch (num) {
        case "=":
            document.getElementById("inp").value = eval(document.getElementById("inp").value);
            break;
        case "c":
            document.getElementById("inp").value = "";
            break;
        default:
            document.getElementById("inp").value += num;
            break;
    }

}
</script>

</body>
</html>
